'''
输入一个表达式，计算出表达式的值（+-*/)
'''
import re


__author__ = 'ZFH'

class calString(object):

    def __init__(self, value):
        self.value = value

    def isprs(self):
        # 判断是否是表达式
        rule = re.compile('\d+')
        rule2 = re.compile('\+|\-|\*|\/')
        rule3 = re.compile('[^\d^\+^\-^\*^\/]')
        res = rule.findall(self.value)
        res2 = rule2.findall(self.value)
        res3 = rule3.findall(self.value)
        if len(res3) == 0:
            if len(res2) == len(res)-1:
                return True
            else:
                return False
        else:
            return False

    def splitString(self):
        # 字符串数字和运算符分离
        if self.isprs():
            rule = re.compile('\d+')
            rule2 = re.compile('\+|\-|\*|\/')
            l = rule.findall(self.value)
            l2 = rule2.findall(self.value)
            count = 0
            t = 0
            # 计算乘除
            for i in l2:
                # 如果最后一个符号不是乘除
                if t < len(l2)-1:
                    if i == '*':
                        l[count] = float(l[count]) * float(l[count+1])
                        l[count+1] = float(l[count+2])
                        l.pop(count+2)
                        count -= 1
                    elif i == '/':
                        l[count] = float(l[count]) / float(l[count+1])
                        l[count+1] = float(l[count+2])
                        l.pop(count+2)
                        count -= 1
                    count += 1
                # 如果最后一个符号是乘除
                else:
                    if i == '*':
                        l[count] = float(l[count]) * float(l[count+1])
                        l.pop(count+1)
                        count -= 1
                    elif i == '/':
                        l[count] = float(l[count]) / float(l[count+1])
                        l.pop(count+1)
                        count -= 1
                    count += 1
                t += 1
            t1 = 0
            # 把乘除变成0之后去掉
            for j in l2:
                if j == '*':
                    l2[t1] = 0
                elif j == '/':
                    l2[t1] = 0
                t1 += 1
            l3 = []
            for k in l2:
                if k != 0:
                    l3.append(k)
            t4 = 0
            count1 = 0
            for i in l3:
                # 如果最后一个符号不是加减
                if t4 < len(l3)-1:
                    if i == '+':
                        l[count1] = float(l[count1]) + float(l[count1+1])
                        l[count1+1] = float(l[count1+2])
                        l.pop(count1+2)
                        count1 -= 1
                    elif i == '-':
                        l[count1] = float(l[count1]) - float(l[count1+1])
                        l[count1+1] = float(l[count1+2])
                        l.pop(count1+2)
                        count1 -= 1
                    count += 1
                # 如果最后一个符号是加减
                else:
                    if i == '+':
                        l[count1] = float(l[count1]) + float(l[count1+1])
                        l.pop(count1+1)
                        count1 -= 1
                    elif i == '-':
                        l[count1] = float(l[count1]) - float(l[count1+1])
                        l.pop(count1+1)
                        count1 -= 1
                count1 += 1
                t4 += 1
            return l[0]
        else:
            return '不是表达式'


inp = input('请输入表达式：')
t = calString(inp)
res = t.splitString()
print(res)
